<template>
	<view>


		<view style="background-color: #FFFFFF; position: sticky; top: 0;z-index: 2;">

			<u-tabs :list="conditionData" :current="tabSelect" keyName="value" :scrollable="false" lineColor="#20C3AA"
				@change="itemChange" :activeStyle="{
						  color:'#20C3AA',
						  fontWeight:'bold',
						  transform:'scal(1.05)'
					  }" :inactiveStyle="{
						  color:'#606266',
						  transform:'scal(1)'
					  }">
			</u-tabs>


		</view>


		<view class="card" v-show="tabSelect == 0" style="margin: 15upx 24upx 60upx;padding: 20upx;z-index: 999;">
			<rich-text :nodes="html" space="nbsp"></rich-text>
		</view>


		<view v-show="tabSelect == 1" style="margin: 0upx 24upx 60upx;">

			<view class="card" style="margin: 20upx 0;padding: 18upx;" v-for="(item, index) in coreData"
				:key="item.title" @click="itemClick(item)">
				<text style="display: block; margin: 20upx 0;">{{item.title}}</text>

				<!-- <view class=""> -->

				<u--image radius="4" :src="baseurl+item.imgUrl" width="100%" height="120px" mode="scaleToFill">
				</u--image>

				<!-- <image :src="baseImageUrl+item.imgUrl" mode="scaleToFill" style="display: block; height: 240upx;width: 100%;"></image> -->
				<!-- </view> -->
			</view>

		</view>


		<view class="card" v-show="tabSelect == 2" style="margin: 15upx 24upx 60upx;">
			<view style="margin: 20upx 0;padding: 18upx;" v-for="(item, index) in modelData" :key="item.id"
				@click="itemClick(item)">

				<text style="display: block; margin: 20upx 0;">{{item.title}}</text>


				<u--image radius="4" :src="baseurl+item.imgUrl" width="100%" height="120px" mode="scaleToFill">
				</u--image>

			</view>
		</view>

		<no-data v-if="isShowNoData"></no-data>

		<u-loadmore :status="loadingStatus" v-if="showloading" @loadmore="clickloadmore"></u-loadmore>

	</view>
</template>

<script>
	import {
		businessCondition,
		enterpriseintroduction,
		corebusiness,
		modelintroduction
	} from '../../../common/api.js';

	export default {
		data() {
			return {
				conditionData: [],
				html: '',
				coreData: [],
				modelData: [],
				tabSelect: 0,
				baseurl: this.baseImageUrl,
				corePageNo: 1,
				modelPageNo: 1,
				pageSize: 10,
				isShowNoData: false,
				showloading: false,
				loadingStatus: 'loading'
			}
		},

		methods: {
			itemChange(item) {
				this.tabSelect = item.index;

				if (0 == this.tabSelect) {
					this.isShowNoData = uni.$u.test.isEmpty(this.html);
				} else if (1 == this.tabSelect) {
					this.isShowNoData = uni.$u.test.isEmpty(this.coreData);
				} else if (2 == this.tabSelect) {
					this.isShowNoData = uni.$u.test.isEmpty(this.modelData);
				}
				this.showloading = false;
				this.loadingStatus = 'loadmore';
			},

			getCompanyIntroData() {
				enterpriseintroduction().then(res => {
					this.html = res;
					uni.stopPullDownRefresh();
					if (0 == this.tabSelect) {
						this.isShowNoData = uni.$u.test.isEmpty(this.html);
					}
				})
			},

			getCoreData() {
				corebusiness({
					params: {
						pageNo: this.corePageNo,
						pageSize: this.pageSize
					}
				}).then(res => {

					if (this.corePageNo == 1) {
						this.coreData = [];
						this.corePageNo++;
						uni.stopPullDownRefresh();

						this.showloading = false;
						this.loadingStatus = 'loadmore';

					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.corePageNo++;

							this.showloading = false;
							this.loadingStatus = 'loadmore';
						} else {
							this.showloading = true;
							this.loadingStatus = 'nomore';
						}
					}

					this.coreData = this.coreData.concat(res);
					console.log(this.coreData);
				})
			},

			getCarIntroData() {
				modelintroduction({
					params: {
						pageNo: this.modelPageNo,
						pageSize: this.pageSize
					}
				}).then(res => {

					if (this.modelPageNo == 1) {
						this.modelData = [];
						this.modelPageNo++;
						uni.stopPullDownRefresh();

						this.showloading = false;
						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.modelPageNo++;

							this.showloading = false;
							this.loadingStatus = 'loadmore';
						} else {
							this.showloading = true;
							this.loadingStatus = 'nomore';
						}
					}

					this.modelData = this.modelData.concat(res);

				})
			},

			itemClick(item) {
				let content = '';
				// 跳转类型:1.外部 2.内部 3.产品
				let type = item.jumpType;
				// 是否有咨询栏(1.有咨询栏，2.无咨询)
				let isInformationColumn = item.isInformationColumn;
				content = type == 1 ? item.connectionAddressLinkUrl : item.internalJump
				if (type == 1 || type == 2) {
					getApp().globalData.content = content;

					let urls = ['', '../activityIntroduction/activitywebview',
						// '../../activity/activityDetail-gather?isInformationColumn=' + isInformationColumn+'&bizNo='+item.id
						'../activityIntroduction/activityIntroduction',
					]

					uni.navigateTo({
						url: urls[type]
					})

				} else if (type == 3) {
					uni.navigateTo({
						url: '../../car/cardetail/cardetail?bizType=7&schemeId=' + item.productLinkUrl
					})
				}

			},

			clickloadmore() {
				if (1 == this.tabSelect) {
					// this.corePageNo ++;
					this.getCoreData();
					this.showloading = true;
					this.loadingStatus = 'loading';
				} else if (2 == this.tabSelect) {
					// this.modelPageNo ++;
					this.getCarIntroData();
					this.showloading = true;
					this.loadingStatus = 'loading';
				}
			},


		},
		onLoad() {
			//请求方式 1
			// uni.$u.http.get("/app/business/condition").then(
			// 	res => {
			// 		console.log(res);
			// 	})

			//请求方式 2
			businessCondition(
				// {
				// 	custom: {
				// 		auth: true,
				// 		toast: false,
				// 		// catch: false
				// 	}
				// }
			).then(
				res => {
					this.conditionData = res;

					if (!uni.$u.test.isEmpty(this.conditionData)) {
						for (let item of this.conditionData) {

							switch (item.dictId) {
								case '3352':
									//请求企业介绍
									this.getCompanyIntroData();
									break;
								case '3353':
									//核心业务
									this.getCoreData();
									break;
								case '3354':
									//车型介绍
									this.getCarIntroData();
									break;
							}
						}
						this.isShowNoData = false;
					} else {
						this.isShowNoData = true;
					}
				}).catch(
				res => {
					this.isShowNoData = true;
				})

		},

		onPullDownRefresh() {
			if (0 == this.tabSelect) {
				this.getCompanyIntroData();
			} else if (1 == this.tabSelect) {
				this.corePageNo = 1;
				this.getCoreData();
			} else if (2 == this.tabSelect) {
				this.modelPageNo = 1;
				this.getCarIntroData();
			}
		},

		onReachBottom() {
			console.log('到底了');

			if (1 == this.tabSelect) {
				// this.corePageNo ++;
				this.getCoreData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			} else if (2 == this.tabSelect) {
				// this.modelPageNo ++;
				this.getCarIntroData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			}
		}




	}
</script>

<style>

</style>
